package cn.bugstack.mybatis.datasource.unpooled;

import java.util.Properties;

import javax.sql.DataSource;

import cn.bugstack.mybatis.datasource.DataSourceFactory;

/**
 * description: 无池化数据源工厂 同样实现数据源工厂接口 
 * taskId：
 * <pre>
 * change history:
 * date             defect#             person                comments
 * ---------------------------------------------------------------------
 * 2024/11/27       ********         zhaochaoyue        create file
 * </pre>
 *
 * @author: zhaochaoyue
 * @date: 2024/11/27 19:10
 * @copyright: 2024
 */
public class UnpooledDataSourceFactory implements DataSourceFactory {
    
    protected Properties properties;
    
    @Override
    public void setProperties(Properties properties) {
        this.properties =properties;
    }

    @Override
    public DataSource getDataSource() {
        UnpooledDataSource unpooledDataSource = new UnpooledDataSource();
        unpooledDataSource.setDriver(properties.getProperty("driver"));
        unpooledDataSource.setUrl(properties.getProperty("url"));
        unpooledDataSource.setUsername(properties.getProperty("username"));
        unpooledDataSource.setPassword(properties.getProperty("password"));
        return unpooledDataSource;
    }
}
